home *** CD-ROM | disk | FTP | other *** search
/ Dr. Windows 3 / dr win3.zip / dr win3 / WINPROGS / UPC12BS1.ZIP / UUCICO / DCP.C < prev    next >
C/C++ Source or Header  |  1993-10-03  |  26KB  |  767 lines

  1. /*--------------------------------------------------------------------*/
  2. /*          d c p . c                                                 */
  3. /*                                                                    */
  4. /*          Main routines for UUCICO                                  */
  5. /*--------------------------------------------------------------------*/
  6.  
  7. /*--------------------------------------------------------------------*/
  8. /*    Changes Copyright (c) 1989-1993 by Kendra Electronic            */
  9. /*    Wonderworks.                                                    */
  10. /*                                                                    */
  11. /*    All rights reserved except those explicitly granted by the      */
  12. /*    UUPC/extended license agreement.                                */
  13. /*--------------------------------------------------------------------*/
  14.  
  15. /*--------------------------------------------------------------------*/
  16. /*    Copyright (c) Richard H. Lamb 1985, 1986, 1987                  */
  17. /*    Changes Copyright (c) Stuart Lynne 1987                         */
  18. /*--------------------------------------------------------------------*/
  19.  
  20. /*
  21.  *    $Id: dcp.c 1.20 1993/10/03 20:37:34 ahd Exp $
  22.  *
  23.  *    $Log: dcp.c $
  24.  * Revision 1.20  1993/10/03  20:37:34  ahd
  25.  * Don't attempt to suspend port if using network protocol suite
  26.  *
  27.  * Revision 1.19  1993/09/30  03:06:28  ahd
  28.  * Move suspend signal handler into suspend2
  29.  *
  30.  * Revision 1.18  1993/09/29  13:18:06  ahd
  31.  * Don't call suspend handler under DOS Turbo C++ (not impletemented, anyway)
  32.  *
  33.  * Revision 1.17  1993/09/29  04:52:03  ahd
  34.  * Suspend port by port name, not modem file name
  35.  *
  36.  * Revision 1.16  1993/09/27  00:48:43  ahd
  37.  * Control UUCICO in passive mode by K. Rommel
  38.  *
  39.  * Revision 1.15  1993/09/20  04:46:34  ahd
  40.  * OS/2 2.x support (BC++ 1.0 support)
  41.  * TCP/IP support from Dave Watt
  42.  * 't' protocol support
  43.  *
  44.  * Revision 1.14  1993/08/02  03:24:59  ahd
  45.  * Further changes in support of Robert Denny's Windows 3.x support
  46.  *
  47.  * Revision 1.13  1993/07/31  16:26:01  ahd
  48.  * Changes in support of Robert Denny's Windows support
  49.  *
  50.  * Revision 1.12  1993/07/22  23:22:27  ahd
  51.  * First pass at changes for Robert Denny's Windows 3.1 support
  52.  *
  53.  * Revision 1.11  1993/05/30  00:01:47  ahd
  54.  * Allow tracing connection via UUCICO -t flag
  55.  *
  56.  * Revision 1.10  1993/04/11  00:35:46  ahd
  57.  * Global edits for year, TEXT, etc.
  58.  *
  59.  * Revision 1.9  1993/04/05  04:32:19  ahd
  60.  * Allow unique send and receive packet sizes
  61.  *
  62.  * Revision 1.8  1993/01/23  19:08:09  ahd
  63.  * Don't update host status at sysend() if hostp is not initialized
  64.  *
  65.  * Revision 1.7  1992/12/18  12:05:57  ahd
  66.  * Suppress duplicate machine state messages to improve OS/2 scrolling
  67.  *
  68.  * Revision 1.6  1992/12/01  04:37:03  ahd
  69.  * Add standard comment block for header
  70.  *
  71.  * Revision 1.5  1992/11/28  19:51:16  ahd
  72.  * If in multitask mode, only open syslog on demand basis
  73.  *
  74.  * Revision 1.4  1992/11/22  21:30:55  ahd
  75.  * Do not bother to strdup() string arguments
  76.  *
  77.  * 25Aug87 - Added a version number - Jal
  78.  * 25Aug87 - Return 0 if contact made with host, or 5 otherwise.
  79.  * 04Sep87 - Bug causing premature sysend() fixed. - Randall Jessup
  80.  * 13May89 - Add date to version message  - Drew Derbyshire
  81.  * 17May89 - Add '-u' (until) option for login processing
  82.  * 01 Oct 89      Add missing function prototypes
  83.  * 28 Nov 89      Add parse of incoming user id for From record
  84.  * 18 Mar 90      Change checktime() calls to Microsoft C 5.1
  85.  */
  86.  
  87. /*--------------------------------------------------------------------*/
  88. /* This program implements a uucico type file transfer and remote     */
  89. /* execution protocol.                                                */
  90. /*                                                                    */
  91. /* Usage:   UUCICO [-s sys]                                           */
  92. /*                 [-r 0|1]                                           */
  93. /*                 [-x debug]                                         */
  94. /*                 [-d hhmm]                                          */
  95. /*                 [-m modem]                                         */
  96. /*                 [-l logfile]                                       */
  97. /*                 [-x debuglevel]                                    */
  98. /*                 [-w userid]                                        */
  99. /*                 [-z bps]                                           */
  100. /*                 [-t]                                               */
  101. /*                                                                    */
  102. /* e.g.                                                               */
  103. /*                                                                    */
  104. /* UUCICO [-x n] -r 0 [-d hhmm]    client mode, wait for an incoming  */
  105. /*                                 call for 'hhmm'.                   */
  106. /* UUCICO [-x n] -s HOST     call the host "HOST".                    */
  107. /* UUCICO [-x n] -s all      call all known hosts in the systems      */
  108. /*                           file.                                    */
  109. /* UUCICO [-x n] -s any      call any host we have work queued for.   */
  110. /* UUCICO [-x n]             same as the above.                       */
  111. /*--------------------------------------------------------------------*/
  112.  
  113. /*--------------------------------------------------------------------*/
  114. /*                        System include files                        */
  115. /*--------------------------------------------------------------------*/
  116.  
  117. #include <stdio.h>
  118. #include <stdlib.h>
  119. #include <string.h>
  120. #include <sys/types.h>
  121. #include <limits.h>
  122. #include <time.h>
  123.  
  124. #ifdef _Windows
  125. #include <Windows.h>
  126. #endif
  127.  
  128. /*--------------------------------------------------------------------*/
  129. /*                      UUPC/extended prototypes                      */
  130. /*--------------------------------------------------------------------*/
  131.  
  132. #include "lib.h"
  133. #include "arpadate.h"
  134. #include "catcher.h"
  135. #include "checktim.h"
  136. #include "dcp.h"
  137. #include "dcplib.h"
  138. #include "dcpstats.h"
  139. #include "dcpsys.h"
  140. #include "dcpxfer.h"
  141. #include "expath.h"
  142. #include "getopt.h"
  143. #include "hlib.h"
  144. #include "hostable.h"
  145. #include "hostatus.h"
  146. #include "lock.h"
  147. #include "logger.h"
  148. #include "modem.h"
  149. #include "security.h"
  150. #include "ssleep.h"
  151. #include "suspend.h"
  152. #include "commlib.h"
  153.  
  154. #if defined(_Windows)
  155. #include "winutil.h"
  156. #endif
  157.  
  158.  
  159. /*--------------------------------------------------------------------*/
  160. /*    Define passive and active polling modes; passive is             */
  161. /*    sometimes refered to as "slave", "active" as master.  Since     */
  162. /*    the roles can actually switch during processing, we avoid       */
  163. /*    the terms here                                                  */
  164. /*--------------------------------------------------------------------*/
  165.  
  166. typedef enum {
  167.       POLL_PASSIVE = 0,       /* We answer the telephone          */
  168.       POLL_ACTIVE  = 1        /* We call out to another host      */
  169.       } POLL_MODE ;
  170.  
  171. /*--------------------------------------------------------------------*/
  172. /*                          Global variables                          */
  173. /*--------------------------------------------------------------------*/
  174.  
  175. size_t s_pktsize;             /* send packet size for protocol       */
  176. size_t r_pktsize;             /* receive packet size for protocol    */
  177.  
  178. FILE *xfer_stream = NULL;        /* stream for file being handled    */
  179. boolean callnow = FALSE;           /* TRUE = ignore time in L.SYS        */
  180. FILE *fwork = NULL, *fsys= NULL ;
  181. FILE *syslog = NULL;
  182. char workfile[FILENAME_MAX];  /* name of current workfile         */
  183. char *Rmtname = nil(char);    /* system we want to call           */
  184. char rmtname[20];             /* system we end up talking to      */
  185. struct HostTable *hostp;
  186. struct HostStats remote_stats; /* host status, as defined by hostatus */
  187.  
  188. static boolean dialed = FALSE;/* True = We attempted a phone call */
  189.  
  190. currentfile();
  191.  
  192. /*-----------------